<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="UTF-8">
    <title>[[${title}]]</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/libs/xadmin/css/font.css" type="text/css">
    <link rel="stylesheet" href="/libs/xadmin/css/xadmin.css" type="text/css">
    <link rel="stylesheet" href="/libs/layer/theme/default/layer.css" type="text/css">
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="/libs/layer/layer.js" charset="utf-8"></script>
</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">登录</div>
    <div id="darkbannerwrap"></div>

    <form method="post">
        <input th:if="${_csrf!=null}"
               type="hidden"
               th:name="${_csrf.parameterName}"
               id="_csrf"
               th:value="${_csrf.token}"/>
        <input name="username" placeholder="用户名" type="text" value="visitor" class="layui-input">
        <hr class="hr15">
        <input name="password" placeholder="密码" value="visitor" type="password"
               class="layui-input">
        <hr class="hr15">
        <input value="登录" style="width:100%;" type="submit">
        <hr class="hr20">
    </form>
</div>

<script th:inline="javascript">
  if (top !== window) {
    top.location.href = window.location.href;
  }
  $(function() {
    $('input[type=submit]').click(function() {
      layer.msg('正在登陆，请稍后。');
      $($('form>input')[3]).attr('disabled', 'disabled');
      let username = $('input[name=username]').val().trim();
      let password = $('input[name=password]').val().trim();
      if (username.length < 1) {
        layer.alert('用户名不能为空');
        return false;
      } else if (username.length > 10) {
        layer.alert('用户名不正确');
        return false;
      }
      if (password.length < 1) {
        layer.alert('密码不能为空');
        return false;
      }
      $.post('/manage/login', {
            'username': username,
            'password': password,
            '_csrf': $('#_csrf').val(),
          }, function(result) {
            if (result.status === 403) {
              window.location.reload();
            }
            if (result.result === true) {
              let url = [[${session.SPRING_SECURITY_SAVED_REQUEST == null ? null:session.SPRING_SECURITY_SAVED_REQUEST.redirectUrl}]];
              let redirectUrl;
              if (!url) {
                redirectUrl = '/manage/index';
              } else {
                let moreString = String(url).substr(url.indexOf('/manage') + 7);
                if (moreString.length > 1 && moreString.indexOf('/') !== -1) {
                  redirectUrl = url;
                } else {
                  redirectUrl = '/manage/index';
                }
              }
              window.location.href = redirectUrl;
            } else {
              layer.msg(result.msg);
            }
            $($('form>input')[3]).removeAttr('disabled');
          },
      );
      return false;
    });
  });
</script>
</body>
</html>
